package com.txf.coomon.net.net_okhttp.listener;

import com.google.gson.JsonElement;
import com.orhanobut.logger.Logger;
import com.txf.coomon.net.net_okhttp.response.AppBaseResponse;
import com.txf.net_okhttp3library.listener.BaseListener;
import com.txf.other_toolslibrary.tools.JsonTools;


/**
 * @title 请求结果回调
 */
public class HttpJsonListener extends BaseListener<JsonElement> {
    @Override
    public void onSuccess(int tag, int code, String message, String body) {
        String strDecode = body;
        Logger.i("--->UN 响应码:  " + code + "\n" +
                "  response.message() : " + message + "\n" +
                "--->UN 请求结果数据:  " + strDecode);
        AppBaseResponse result = JsonTools.fromJson(strDecode, AppBaseResponse.class);
        if (result == null) {
            onError(tag, -7, "服务器数据异常");
            return;
        }
        if (result.getCode() == 200) {
            onSuccess(tag, result.getData(), result.getMsg());
        } else {
            onError(tag, result.getCode(), result.getMsg());
        }
    }

    public void onSuccess(int tag, JsonElement data, String message) {

    }

    @Override
    public void onError(int tag, int error, String message) {

    }

}
